import { login, getProvider } from "@/utils/auth.js";
import utils from "@/utils/utils";

export default {
  //APP 手机号一键登录
  async appPhoneNumberLogin() {
    try {
      let oauth = await getProvider("oauth")//返回登录选项
      if (!oauth.includes("univerify")) return
      await preLogin("univerify") //预登录
      let univerifyStyle = {
        "fullScreen": true,
      }
      return await login("univerify", univerifyStyle)
    } catch (error) {
      uni.$uv.toast(error)
    }
  },

  //APP 微信登录
  async appWxLogin() {
    let oauth = await getProvider("oauth")//返回登录选项
    if (!oauth.includes("weixin")) return
    await login()
  },

  //APP 支付宝登录
  appAplipayLogin() {
    let backUrl = 'https://www.baihuayuan.com/back.html';//页面跳回地址,授权成功之后会在支付宝中打开这个地址
    let appid = '2021001168621379'; //商户的APPID 
    let aplipayAuthUrl = 'https://openauth.alipay.com/oauth2/publicAppAuthorize.htm';
    let urls = `${aplipayAuthUrl}?app_id=${appid}&scope=auth_userinfo&redirect_uri=${backUrl}`;
    urls = encodeURIComponent(urls);//将地址编码成浏览器访问的格式
    // 判断平台
    let link
    if (plus.os.name == 'Android') {
      link = 'alipays://platformapi/startapp?appId=20000067&url=' + urls
    } else if (plus.os.name == 'iOS') {
      link = 'alipay://platformapi/startapp?appId=20000067&url=' + urls
    }
    plus.runtime.openURL(
      link,
      async res => {
        await utils.showModal({ content: '本机未检测到对应客户端，是否打开浏览器访问页面？' })
      },
      'com.eg.android.AlipayGphone'
    );
  }
}